package cn.dgut.jy.soro.config;

import cn.dgut.jy.soro.interceptor.IsLoginInterceptor;
import cn.dgut.jy.soro.interceptor.IsNotLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/join").setViewName("join");
        registry.addViewController("/about").setViewName("about");
        registry.addViewController("/cat").setViewName("cat");
        registry.addViewController("/dog").setViewName("dog");
        //registry.addViewController("/cart").setViewName("cart");
        registry.addViewController("/buy").setViewName("buy");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new IsLoginInterceptor()).addPathPatterns("/login");
        /*registry.addInterceptor(new IsNotLoginInterceptor()).addPathPatterns("/cart");
        registry.addInterceptor(new IsNotLoginInterceptor()).addPathPatterns("/buy");*/
        registry.addInterceptor(new IsNotLoginInterceptor()).addPathPatterns("/logout");
    }
}
